#include "head.h"

int putsText(const char* arg,int netfd,stack1_t dir){
    char path[4096];
    onePath(arg,path,&dir);

    train_t train;
    bzero(&train,sizeof(train));
   // strcat(path,"demo");
    printf("puts path: %s\n",path);
    char filename[1024]={0};
    int fd=open(path,O_WRONLY|O_TRUNC|O_CREAT,0776);
    if(fd==-1){
        int ret=-1;
        send(netfd,&ret,sizeof(int),MSG_NOSIGNAL);//发送错误码
        return -1;
    }
    int ret=0;
    send(netfd,&ret,sizeof(int),MSG_NOSIGNAL);
    
    while(1){
        bzero(&train,sizeof(train));
        int retval=recvn(netfd,&train.length,sizeof(train.length));
        if(train.length==0){
            break;
        }
        printf("已接受%d\n",retval);
        recvn(netfd,train.data,train.length);
        write(fd,train.data,train.length);
    }
    return 0;

}
